package com.ebt.m.proposal_v2.bean;

import android.util.Log;

import com.ebt.m.proposal_v2.EbtEqualUtil;
import com.ebt.m.proposal_v2.dao.response.BusinessConfig;

import java.util.ArrayList;
import java.util.List;

/**
 * 计划书
 *
 * @author archer.qi
 *         Created on 2017/5/12.
 */
public class ProposalEntity {

    /* 提取码，唯一标识*/
    public String pickNum;
    /* 名称*/
    public String proposalName;
    /* 描述*/
    public String description;
    /* 缩略图*/
    public String thumbnail;
    /* 总保额*/
    public double totalCoverage;
    /* 总保费*/
    public double totalPremium;

    /* 投保人*/
    public ApplicantEntity applicant;
    /* 多被保人*/
    public List<InsuredEntity> insured;

    public BusinessConfig businessConfig;

    public int shouldSaveClient;

    public String accMaxAge;
    public String accMinAge;
    public String accOccupation;
    public String accSex;

    public ProposalEntity(){

    }

    //没问题
    public ProposalEntity(ProposalEntity org){
        this.pickNum = org.pickNum;
        this.proposalName = org.proposalName;
        this.description = org.description;
        this.thumbnail = org.thumbnail;
        this.totalCoverage = org.totalCoverage;
        this.totalPremium = org.totalPremium;
        this.shouldSaveClient = org.shouldSaveClient;
        if (org.businessConfig != null) {
            this.businessConfig = new BusinessConfig(org.businessConfig);
        }
        if (org.applicant != null) {
            this.applicant = new ApplicantEntity(org.applicant);
        }
        this.insured = new ArrayList<>();
        if (org.insured != null){
            for (InsuredEntity insuredEntity : org.insured){
                this.insured.add(insuredEntity);
            }
        }
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null){
            return false;
        }
        if (!(obj instanceof ProposalEntity)){
            return false;
        }
        ProposalEntity a = (ProposalEntity)obj;

        boolean equals = (EbtEqualUtil.stringEquals(this.pickNum, a.pickNum)
                && EbtEqualUtil.stringEquals(this.proposalName, a.proposalName)
                && EbtEqualUtil.stringEquals(this.description, a.description)
                && EbtEqualUtil.stringEquals(this.thumbnail, a.thumbnail)
                && EbtEqualUtil.doubleEquals(this.totalCoverage, a.totalCoverage)
                && EbtEqualUtil.doubleEquals(this.totalPremium, a.totalPremium)
                && (this.shouldSaveClient == a.shouldSaveClient)
                && (EbtEqualUtil.applicantEntityEquals(this.applicant, a.applicant)));

        return equals;
    }

    public int getMainRiskProductId(){
        int productId = 0;
        if (insured != null){
            for (InsuredEntity insuredEntity : insured){
                if (productId != 0){
                    break;
                }
                if (insuredEntity == null || insuredEntity.risk == null){
                    continue;
                }
                for (InsuranceEntity entity : insuredEntity.risk){
                    if (entity == null){
                        continue;
                    }
                    if(entity.isMain()){
                        productId = entity.productId;
                        break;
                    }
                }
            }
        }
        return productId;
    }
}
